import React from 'react';
import { inject, observer } from 'mobx-react';
import { Modal } from 'antd';
const confirm = Modal.confirm;
import { WeaTableNew } from 'comsMobx';
const WeaTable = WeaTableNew.WeaTable;
import InstockInfoDialog from "./InsrockInfoDialog"
import { WeaLocaleProvider } from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;

@inject('cptInstockStore')
@observer
class HistoryInstock extends React.Component {
    constructor(props) {
        super(props);
    }
    render() {
        const { cptInstockStore } = this.props;
        const { tableStore, } = cptInstockStore;
        return (<div >
            <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@bsfvbx`}
                comsWeaTableStore={tableStore}
                hasOrder={true}
                needScroll={true}
                getColumns={c=>this.reRenderColumns(c)}
                onOperatesClick={this.onOperatesClick.bind(this)}
            />
            <InstockInfoDialog ecId={`${this && this.props && this.props.ecId || ''}_InstockInfoDialog@e43cln`} contentStore={cptInstockStore} />
        </div>)

    }
    onOperatesClick = (record, index, operate, flag) => {
        const { cptInstockStore } = this.props;
        const { instockInfoStore } = cptInstockStore;
        let that = this;
        let state = record.ischecked;
        if (flag == 0) {  //查看详情
            instockInfoStore.handleDialog(true, { instockid: record.randomFieldId }, state, 0);

        } else if (flag == 1) {  //收回
            confirm({
                title: getLabel(15172, '系统提示'),
                content: getLabel(83583, '您确定将此入库单收回吗?'),
                onOk() {
                    instockInfoStore.doRejectInstock({ 'instockid': record.randomFieldId }, cptInstockStore);
                },
                onCancel() { },
            });
        } else if (flag == 2) {   //重新申请
            instockInfoStore.handleDialog(true, { instockid: record.randomFieldId }, state, 2);
        }else if (flag == 3) {   //删除
            confirm({
                title: getLabel(15172, '系统提示'),
                content: getLabel(83600, '您确认要删除吗?'),
                onOk() {
                    cptInstockStore.doDelete({'instockid': record.randomFieldId });
                },
                onCancel() { },
            });
        }
    }

    reRenderColumns(columns){
        const { cptInstockStore } = this.props;
        const { instockInfoStore } = cptInstockStore;
        columns.forEach(c=>{
            if(c.dataIndex=='tmpid'){
                c.render = function(text, record){
                    let valueSpan = record[c.dataIndex + "span"] !== undefined ? record[c.dataIndex + "span"] : record[c.dataIndex];
                    return <a onClick={()=>{instockInfoStore.handleDialog(true, { instockid: record.tmpid}, record.ischecked, 0);}}>{valueSpan}</a>
                }
            } else {
              return c;
            }
        })
        return columns;
    }
    

}

export default HistoryInstock;